<template>
  <div class="TableTmpl" @click="click">
    <div class="tableBox">
      <el-collapse-transition>
        <div
          class="tableBox-search"
          v-show="search.visible"
          ref="TableTmplSearch"
        >
          <slot name="search"></slot>
        </div>
      </el-collapse-transition>
      <div class="tableBox-opertaion" v-if="!hideOperation">
        <slot name="opertaion"></slot>
        <div class="tableBox-opertaion-right">
          <el-tooltip
            class="item"
            effect="dark"
            content="切换显示模式"
            placement="top"
            v-if="type"
          >
            <div class="operation-type cursor">
              <div
                class="table"
                v-if="type === 'card'"
                @click="setType('table')"
              >
                <i></i><i></i><i></i>
              </div>
              <i
                class="card el-icon-menu cursor"
                v-if="type === 'table'"
                @click="setType('card')"
              ></i>
            </div>
          </el-tooltip>
          <el-tooltip
            class="item"
            effect="dark"
            content="高级查询"
            placement="top"
            v-if="!hideAdSearch"
          >
            <el-button
              icon="el-icon-search"
              circle
              size="small"
              @click="toggleAdSearch"
            ></el-button>
          </el-tooltip>
          <el-tooltip
            class="item"
            effect="dark"
            content="刷新列表"
            placement="top"
          >
            <el-button
              icon="el-icon-refresh"
              circle
              size="small"
              @click="refresh"
            ></el-button>
          </el-tooltip>
        </div>
      </div>
      <div class="tableBox-table">
        <slot name="table" class="tableBox-table-main"></slot>
      </div>
      <div class="tableBox-pagination">
        <slot name="pagination"></slot>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: "TableTmpl",
  data() {
    return {
      search: {
        visible: true,
      },
    };
  },
  components: {},
  props: {
    hideOperation: {
      type: Boolean,
      default: false,
    },
    AdSearch: {
      type: [Boolean, Object],
      default: null,
    },
    type: {
      type: [String],
      default: null,
    },

    // hideAdSearch: {
    //   type: Boolean,
    //   default: false
    // }
  },
  computed: {
    hideAdSearch() {
      return this.AdSearch === null;
    },
  },
  mounted() {
    // this.$refs.TableTmplSearch.children[0].children[0].style.display = 'none';
  },
  methods: {
    refresh() {
      this.$emit("refresh");
    },
    click() {
      this.$emit("click");
    },
    toggleAdSearch() {
      this.$emit("update:AdSearch", !this.AdSearch);
    },
    setType(type) {
      this.$emit("update:type", type);
    },
  },
};
</script>

<style lang="scss" scoped>
@import "@/MUI/style/var.scss";

.tableBox-opertaion {
  margin-bottom: px2(20);
  padding-right: px2(100);
  position: relative;

  .tableBox-opertaion-right {
    position: absolute;
    right: px2(0);
    top: 50%;
    transform: translateY(-50%);
    vertical-align: middle;
    .operation-type {
      margin-right: px2(20);
      vertical-align: middle;
      display: inline-block;
      width: px2(30);
      height: px2(30);
      position: relative;
      .table {
        display: inline-block;
        vertical-align: middle;
        position: absolute;
        left: 50%;
        top: 50%;
        transform: translate(-50%, -50%);
        i {
          display: block;
          width: px2(18);
          height: px2(2);
          background: $fontColorL;
          margin: px2(4) 0;

          &:first-child {
            //margin-top: 0;
          }
          &:last-child {
            //margin-bottom: 0;
          }
        }
      }
      .card {
        font-size: px2(20);
        color: $fontColor;
        position: absolute;
        left: 50%;
        top: 50%;
        transform: translate(-50%, -50%);
      }
    }
  }
}
.tableBox-table {
  width: 100%;
  margin-bottom: px2(20);
}
.tableBox-pagination {
  text-align: right;
}
</style>
